package handler

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"work/src/work/internal/params"
	"work/src/work/internal/service"
)

type PlayVideoHandler struct {
	PlayVideoService service.PlayVideoImpl
	PlayReq          params.PlayRequest
}

func NewPlayVideoHandler() *PlayVideoHandler {
	return &PlayVideoHandler{
		PlayVideoService: service.NewPlayVideoMax(),
		PlayReq:          params.PlayRequest{},
	}
}
func (p *PlayVideoHandler) PlayVideo(c *gin.Context) {
	if err := c.ShouldBindJSON(&p.PlayReq); err != nil {
		// 返回错误信息
		// gin.H封装了生成json数据的工具
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}

	list := p.PlayVideoService.PlayVideo()

	c.JSON(http.StatusOK, gin.H{
		"data": list,
	})
}
